<template>
	<view class="flex j-sb">
		<view class="brand_class height-100 bg-white">
			<scroll-view class="scroll-Y" scroll-y="true" scroll-x="false">
				<block v-for="(item,index) in sale_warehouse_type" :key="index">
					<view v-if="item.value!='quote'" class="item" :class="{'active':brandIndex==index}" @click="handleBrand(index,item)">
						<text>{{item.label}}</text>
					</view>
				</block>

			</scroll-view>
		</view>
		<view class="flex-1 pr-3">
			<scroll-view class="scroll-Y" scroll-y="true" scroll-x="false">
				<view class="bg-white p-4 tags_search mt-3 pb-1 rounded-10" v-for="(item,index) in menuGrid"
					:key="index">
					<view class="mb-3 font-bold">{{item.name}}</view>
					<view class="">
						<view class="item" v-for="(l,li) in item.list" :key="li" @click="navigateTos(l.path)">{{l.name}}
						</view>

					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		brandEnableList
	} from '@/common/api/brand.js'
	export default {
		data() {
			return {
				brandIndex: 0,
				brandList: [],
				menuGrid: [],
				menuUserList: [],
				menuList: [{
						name: '仓库',
						value: 'query',
						list: [{
							name: '我的库存',
							path: 'pages/warehouse/product/index?type=product'
						}, {
							name: '它库库存',
							path: 'pages/warehouse/product/index?type=itLibrary'
						}, {
							name: '客户管理',
							path: 'pages/warehouse/customer/index'
						}]
					},
					{
						name: '销售',
						value: 'sale',
						list: [{
							name: '销售出库',
							path: 'pages/warehouse/outbound/index'
						}, {
							name: '销售退货',
							path: 'pages/warehouse/returns/index'
						}, {
							name: '销售记录',
							path: 'pages/warehouse/salesRecord/index'
						}]
					},
					{
						name: '调拨',
						value: 'allot',
						list: [{
							name: '商品调拨',
							path: 'pages/warehouse/allot/index'
						}, {
							name: '调拨审核',
							path: 'pages/warehouse/transferAudit/index'
						}, {
							name: '调拨记录',
							path: 'pages/warehouse/transferRecord/index'
						}]
					}
				]
			}
		},
		async onLoad() {
			await this.cacheHelper.updateUserInfo();
			await this.saleWarehouseType();
			await this.getWareLists();
		},
		methods: {
			// mobileConfig  0仓库、1 销售、2 调拨 
			getWareLists() {
				this.menuUserList = [];
				this.menuGrid = [];
				let mobileConfig = this.app_user_info.mobileConfig ? this.app_user_info.mobileConfig.split(',') : [];
				this.menuList.forEach(i => {
					mobileConfig.forEach(m => {
						if (i.value == m) {
							this.menuUserList.push(i);
						}
					})
				})
				this.menuGrid = this.menuUserList;
			},
			handleBrand(index, item) {
				let mobileConfig = this.app_user_info.mobileConfig ? this.app_user_info.mobileConfig.split(',') : [];
				this.brandIndex = index;
				this.menuGrid = [];
				this.menuList.forEach(i => {
					mobileConfig.forEach(m => {
						if (i.value == m) {
							this.menuGrid.push(i);
						}
					})
				})
				if(this.menuGrid.length==0){
					uni.$u.toast('暂无权限，请联系管理员');
				}


			},
			navigateTos(path){
				let val=this.sale_warehouse_type[this.brandIndex].value
				if(this.app_user_info.mobileConfig.indexOf(val)==-1){
					uni.$u.toast('暂无权限，请联系管理员');
				}else{
					uni.navigateTo({
						url: '/'+path,
					})
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.brand_class {
		width: 160rpx;
		margin-right: 20rpx;

		.item {
			display: flex;
			display: -webkit-flex;
			justify-content: center;
			align-items: center;
			height: 88rpx;
			position: relative;

			&::before {
				content: '';
				position: absolute;
				left: 0;
				top: 25%;
				bottom: 25%;
				width: 2px;
				background-color: transparent;
			}

			&.active {
				color: var(--primary);

				&::before {
					background-color: var(--primary);
				}
			}
		}
	}

	.tags_search {
		.item {
			width: 160rpx;
			height: 54rpx;
			line-height: 54rpx;
			border-radius: 10rpx;
			border: 2rpx solid #C3C3C3;
			margin-right: 50rpx;
			color: #4F4F4F;
			text-align: center;
			display: inline-block;
			margin-bottom: 30rpx;

		}
	}
</style>